class Solution:
    def divide(self, dividend: int, divisor: int) -> int:
        st = False
        exp = []
        if dividend < 0 and divisor > 0 or dividend > 0 and divisor < 0:
            st = True
        a, b, i = abs(dividend), abs(divisor), abs(divisor)
        while i <= a:
            exp.append(i)
            i += i
        res = 0
        for i in range(len(exp) - 1, -1, -1):
            if a >= exp[i]:
                a -= exp[i]
                res += 1 << i
        if st:
            res = -res
        if res > 2 ** 31 - 1 or res < -2 ** 31:
            res = 2 ** 31 - 1
        return res


print(Solution().divide(1, 1))



